<template>
  <div>
    <a-select
      show-search
      placeholder="请选择"
      option-filter-prop="children"
      @change="handleChange"
      :disabled="state.disabled"
      v-model="selected"
    >
      <a-select-option v-for="item in list" :key="item.id" :value="item.id">
        {{item.name}}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
  import { getPartnerList } from '@/api/proxy'

  export default {
    name: 'PartnerSelection',
    props: {
      value: {
        type: Array,
        default: () => []
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      value: {
        handler: function (value) {
          this.selected = value
        }
      },
      disabled: {
        handler: function (value) {
          this.state.disabled = value
        },
        immediate: true
      }
    },
    created () {
      getPartnerList({ per_page: 999 }).then(res => {
        this.list = res.data
      })
    },
    data () {
      return {
        list: [],
        selected: [],
        state: {
          disabled: false
        }
      }
    },
    methods: {
      handleChange (value) {
        this.$emit('change', [value])
        this.$emit('input', [value])
      }
    }
  }
</script>

<style scoped>

</style>
